<?php

if ( ! defined('BASEPATH')) 
    exit('No direct script access allowed');

class Home extends CI_Controller{
    private $page;
    public function __construct() {
        parent::__construct();
        $user_data = $this->session->all_userdata();
        if (isset($user_data["logged_in"]) && $user_data["logged_in"] == TRUE) {
            $this->page["header"] = $this->load->view("part/header_login", '', true);
        } else {
            $this->page["header"] = $this->load->view("part/header_no_login", '', true);
        }
    }
    /**
     * Action   :index
     * Purpose  :View the list of all field and some of its tags
     * Date     :25/04/2012
     * Author   :Dang Huy Hoa
     */
    public function index(){
        $user_data = $this->session->all_userdata();
        if (isset($user_data["logged_in"]) && $user_data["logged_in"] == TRUE) {
            $page["header"] = $this->load->view("part/header_login", '', true);
        } else {
            $page["header"] = $this->load->view("part/header_no_login", '', true);
        }
        
        $this->load->model('home_model', 'home');
        
        $data["field"] = $this->home->getField();
        $data["tag"] = $this->home->getTag();
        $data["path"] = $this->home->getPath();
        $page["content"] = $this->load->view("page/home", $data, true);
        $this->load->view("layout", $page);//
    }
    /**
     * Action   :field
     * Purpose  :Show all tags and paths in field has #id
     * Date     :
     * Author   :
     */
    public function field($id){
        $page=$this->page;
        
        $this->load->model('home_model', 'home');
        
        $data["field"] = $this->home->getField();
        $data["tag"] = $this->home->getTag();
        $path = $this->home->getPathByFieldId($id);
        if ($path != null) {
            $data["path"] = $path;
        } else {
            $data["message"]["info"] = "Không có lộ trình nào trong lĩnh vực này.";
            $data["path"] = "";
        }
        $page["content"] = $this->load->view("page/home", $data, true);
        $this->load->view("layout", $page);
    }
    /**
     * Action   :tag
     * Purpose  :Return to home page (Home/index)
     * Date     :
     * Author   :
     */
    public function tag($id){
        $page=$this->page;
        
        $this->load->model('home_model', 'home');
        
        $data["field"] = $this->home->getField();
        $data["tag"] = $this->home->getTag();
        $path = $this->home->getPathByTagId($id);
        if ($path != null) {
            $data["path"] = $path;
        } else {
            $data["path"] = "Không có lộ trình nào thuộc chủ đề này.";
        }
        $page["content"] = $this->load->view("page/home", $data, true);
        $this->load->view("layout", $page);
    }
    
    public function test() {
        $page=$this->page;
        
        $this->load->model('home_model', 'home');
        
        $data["field"] = $this->home->getField();
        $data["tag"] = $this->home->getTag();
        $data["path"] = $this->home->getPath();
        //$data['popular']= $this->home->getPopularPath();
        $this->load->view("home", $data);
    }
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */